package com.example.chartview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View

class ArcView(context: Context, attributeSet: AttributeSet) : View(context, attributeSet) {
    val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        style = Paint.Style.STROKE
        strokeWidth = 40F
    }
    private val rect = RectF()
    private val offsetAngle = 10f
    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        super.onSizeChanged(w, h, oldw, oldh)
        val size = w.toFloat().coerceAtMost(h.toFloat()) / 10f
        rect.set(size * 0.75f, size * 0.75f, size * 1.5f, size * 1.5f)
    }


    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        paint.color = Color.BLACK
        canvas.drawArc(rect, offsetAngle, 90F - offsetAngle, false, paint)
        paint.color = Color.RED

        canvas.drawArc(rect, 90F + offsetAngle, 90F - offsetAngle, false, paint)
        paint.color = Color.BLUE

        canvas.drawArc(rect, 180F + offsetAngle, 90F - offsetAngle, false, paint)
        paint.color = Color.YELLOW

        canvas.drawArc(rect, 270F + offsetAngle, 90F - offsetAngle, false, paint)
    }
}